<%@codepage="65001"%>
<%session.codepage="65001"%>
<!-- #include virtual=/inc/dbConn.asp -->
<!-- #include virtual=/inc/function.asp -->
<%
	fullLotNo = Request("fullLotNo")
	lotSubNo = Request("lotSubNo")

	Set orderRs=Server.CreateObject("ADODB.RecordSet")
	SQL = "SELECT A.*, B.company, P.prdNm, P.etcPrdCd FROM tblOrder A " & _
		  "	LEFT JOIN tblCompany B ON A.compCd=B.compCd " & _
		  "	LEFT JOIN tblProduct P ON A.prdCd=P.prdCd " & _
		  "WHERE A.lotYear+A.lotNo='" & fullLotNo & "' AND A.lotSubNo=" & lotSubNo
	orderRs.open SQL, dbCon
	If orderRs.eof Or orderRs.bof Then 
	Else 
		Do Until orderRs.eof Or orderRs.bof
			prdNm = orderRs("prdNm")
			etcPrdCd= orderRs("etcPrdCd")
			If Trim(etcPrdCd) <> "" Then 
				'etcPrdCd= " (" & orderRs("etcPrdCd") & ")"
				etcPrdCd = orderRs("etcPrdCd")
			End If 
			deliveryDt = orderRs("deliveryDt")
			company = orderRs("company")
			sourceLotNo = orderRs("sourceLotNo")
			sourceSize = orderRs("sourceSize")
			workMemo = orderRs("workMemo")
			compMemo = orderRs("compMemo")
			remarks = orderRs("remarks")
			planDt = orderRs("planDt")
			qty = FormatNumber(orderRs("qty"),0)

		orderRs.movenext
		Loop 
	End If
	printTime = date() & " " & time()
	showLotNo = Replace(fullLotNo & "-" & lotSubNo,"-0","")
%>
<!-- #include virtual=/inc/header.inc.asp -->  
<script language = "JavaScript" src="/inc/js/ScriptX_TAG_SCM.js"></script>
<script>initScriptX("contexts", "100%", "100%"); </script>

<script for=window event=onload>
	printWindow(document.contexts, "<%=printTime%>");
	//self.close();
</script>


<script language="JavaScript">	 
	function printWindow(objName, DAY2) {
		var footer = "출력일시 : " + DAY2;
		objName.printing.header = "";
		objName.printing.footer = footer;
		objName.printing.portrait = true; // false 는 가로인쇄
		objName.printing.leftMargin = 15.0;
		objName.printing.topMargin = 15.0;
		objName.printing.rightMargin = 15.0;
		objName.printing.bottomMargin = 1.0;
		objName.printing.Print(false);
	}
</script>
<style>
.table_com {
	background-color: #FFFFFF;
	clear: both;
	border: 1px solid #000000; 
	font-size: 10px;
	line-height: 18px;
	padding: 3px 1px 3px 1px;
}
.table_com_orange {
	background-color: #FFFFFF;
	clear: both;
	border: 1px solid #ff6633; 
	border-bottom: 5px solid #ff6633; 
	font-size: 10px;
	line-height: 18px;
	padding: 3px 1px 3px 1px;
}
.table_com_cell td {
	background-color: #FFFFFF;
	clear: both;
	border-right: 1px solid #000000; 
	border-bottom: 1px solid #000000; 
	border-top: 1px solid #000000; 
	font-size: 11px;
	line-height: 18px;
	padding: 3px 1px 3px 1px;
}
.P_0rb0 {
	background-color: #FFFFFF;
	clear: both;
	border-right: 1px solid #000000; 
	border-bottom: 1px solid #000000; 
	font-size: 11px;
	line-height: 15px;
	padding: 3px 1px 3px 1px;
}
.P_0rbl {
	background-color: #FFFFFF;
	clear: both;
	border-right: 1px solid #000000; 
	border-bottom: 1px solid #000000; 
	border-left: 1px solid #000000; 
	font-size: 11px;
	line-height: 15px;
	padding: 3px 1px 3px 1px;
}
.P_trb0 {
	background-color: #FFFFFF;
	clear: both;
	border-right: 1px solid #000000; 
	border-bottom: 1px solid #000000; 
	border-top: 1px solid #000000; 
	font-size: 11px;
	line-height: 15px;
	padding: 3px 1px 3px 1px;
}
.P_trbl {
	background-color: #FFFFFF;
	clear: both;
	border-right: 1px solid #000000; 
	border-bottom: 1px solid #000000; 
	border-top: 1px solid #000000; 
	border-left: 1px solid #000000; 
	font-size: 11px;
	line-height: 15px;
	padding: 3px 1px 3px 1px;
}
</style>

<%	
	If Trim(etcPrdCd) <> "" Then
		css = "table_com_orange"
	Else
		css = "table_com"
	End If 
%>
 
<BODY topmargin="0" leftmargin="0">
	<table width="99.5%" cellpadding="0" cellspacing="0" class="<%=css%>">
		<tr>
			<td>
				<table width="100%" cellpadding="0" cellspacing="0" border="0">
					<tr>
						<td width="30%" style="padding-left:20px;height:45px;text-align:left">&nbsp; &nbsp;</td>
						<td width="40%" style="text-align:center;font-size:15pt;font-weight:bold;height:40px">작업지시서</td>
						<td width="30%" style="height:40px" nowrap>&nbsp; &nbsp;</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
	<table width="99.5%" cellpadding="0" cellspacing="0">
		<tr>
			<td style="height:10px"></td>
		</tr>
	</table>
	<table width="99.5%" cellpadding="0" cellspacing="0">
		<tr>
			<td width="20%" class="P_trbl" style="text-align:center;height:30px;font-size:13px;font-weight:bold">LOT NO</td>
			<td width="30%" class="P_trb0" style="padding-left:20px;height:30px;font-size:12px"><%=showLotNo%>&nbsp;</td>
			<td width="20%" class="P_trb0" style="text-align:center;height:30px;font-size:13px;font-weight:bold">납기일/수량</td>
			<td width="30%" class="P_trb0" style="padding-left:20px;height:30px;font-size:12px"><%=deliveryDt%> / <%=qty%> EA&nbsp;</td>
		</tr>
		<tr>
			<td width="20%" class="P_0rbl" style="text-align:center;height:30px;font-size:13px;font-weight:bold">제품명</td>
			<td width="30%" class="P_0rb0" style="padding-left:20px;height:30px;font-size:12px"><%=prdNm%>&nbsp;</td>
			<td width="20%" class="P_0rb0" style="text-align:center;height:30px;font-size:13px;font-weight:bold">발주처</td>
			<td width="30%" class="P_0rb0" style="padding-left:20px;height:30px;font-size:12px"><%=Company%>&nbsp;</td>
		</tr>
		<tr>
			<td width="20%" class="P_0rbl" style="text-align:center;height:30px;font-size:13px;font-weight:bold">발주처코드</td>
			<td width="30%" class="P_0rb0" style="padding-left:20px;height:30px;font-size:12px"><%=etcPrdCd%>&nbsp;</td>
			<td width="20%" class="P_0rb0" style="text-align:center;height:30px;font-size:13px;font-weight:bold">작업예정일</td>
			<td width="30%" class="P_0rb0" style="padding-left:20px;height:30px;font-size:12px"><%=planDt%>&nbsp;</td>
		</tr>
		<tr>
			<td width="20%" class="P_0rbl" style="text-align:center;height:30px;font-size:13px;font-weight:bold">자재 LOT NO</td>
			<td width="30%" class="P_0rb0" style="padding-left:20px;height:30px;font-size:12px"><%=sourceLotNo%>&nbsp;</td>
			<td width="20%" class="P_0rb0" style="text-align:center;height:30px;font-size:13px;font-weight:bold">자재규격</td>
			<td width="30%" class="P_0rb0" style="padding-left:20px;height:30px;font-size:12px"><%=sourceSize%>&nbsp;</td>
		</tr>
		<% If compMemo <> "" Then %>
		<tr>
			<td width="20%" class="P_0rbl" style="text-align:center;font-size:13px;font-weight:bold">발주처 특사항</td>
			<td width="80%" class="P_0rb0" colspan="3" style="text-align:left;vertical-align:text-top;height:70px;font-size:11px;padding: 10px 10px 10px 10px"><%=compMemo%>&nbsp;</td>
		</tr>
		<% End If %>
		<% If workMemo <> "" Then %>
		<tr>
			<td width="20%" class="P_0rbl" style="text-align:center;;font-size:13px;font-weight:bold">작업중 특사항</td>
			<td width="80%" class="P_0rb0" colspan="3" style="text-align:left;vertical-align:text-top;height:70px;font-size:11px;padding: 10px 10px 10px 10px"><%=workMemo%>&nbsp;</td>
		</tr>
		<% End If %>
		<% If remarks <> "" Then %>
		<tr>
			<td width="20%" class="P_0rbl" style="text-align:center;font-size:13px;font-weight:bold">비 고</td>
			<td width="80%" class="P_0rb0" colspan="3" style="text-align:left;vertical-align:text-top;height:70px;font-size:11px;padding: 10px 10px 10px 10px"><%=remarks%>&nbsp;</td>
		</tr>
		<% End If %>
	</table>
	<table width="99.5%" cellpadding="0" cellspacing="0">
		<tr>
			<td style="height:10px"></td>
		</tr>
	</table>		
	<table width="99.5%" cellpadding="0" cellspacing="0">
		<tr>
			<td width="4%" class="P_trbl" style="text-align:center;height:30px;font-size:13px;font-weight:bold">No</td>
			<td width="16%" class="P_trb0" style="text-align:center;height:30px;font-size:13px;font-weight:bold">공정</td>
			<td width="12%" class="P_trb0" style="text-align:center;height:30px;font-size:13px;font-weight:bold">작업자</td>
			<td width="13%" class="P_trb0" style="text-align:center;height:30px;font-size:13px;font-weight:bold">작업일</td>
			<td width="25%" class="P_trb0" style="text-align:center;height:30px;font-size:13px;font-weight:bold">작업</td>
			<td width="30%" class="P_trb0" style="text-align:center;height:30px;font-size:13px;font-weight:bold">작업시간</td>
		</tr>
		<%
			Set procRs=Server.CreateObject("ADODB.RecordSet")	
			procSQL = "SELECT A.*, B.processNm, C.userNm FROM tblOrderResult A LEFT JOIN tblUnitProcess B ON A.processCd=B.processCd " & _
					  " LEFT JOIN tblUser C ON A.userId=C.userId " & _
					  " WHERE A.lotYear+A.lotNo='" & fullLotNo & "' AND A.lotSubNo=" & lotSubNo & " AND A.flag='Y' ORDER BY A.rank"
					
			vRest = 1
			procRs.open procSQL, dbCon
			If procRs.eof Or procRs.bof Then 
			Else 
				Do Until procRs.eof Or procRs.bof
					rank = procRs("rank")
					procNm = procRs("processNm")
					userNm = procRs("userNm")
					workDt = procRs("workDt")
					working = procRs("working")
					execTime = procRs("execTime")
					goodQty = procRs("goodQty")
					badQty = procRs("badQty")
					etc = procRs("etc")
					If etc = "" Then etc = "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" End If 
					If goodQty = "0" Then goodQty = "&nbsp;" End If 
					If badQty = "0" Then badQty = "&nbsp;" End If 
					If procRs("type") = "10" Then '## 가공
						execTime = "장비 : " & etc & " / 수량 : " & goodQty
					End If 
					If procRs("type") = "20" Then '## 검사
						execTime = "불량수량 : " & badQty
						working = "양품 : " & goodQty
					End If 
					If procRs("type") = "90" Then '## 포장
						execTime = "출하일 : " & etc
						working = "출하수량 : " & goodQty
					End If 
					rest = rank Mod 100

					If (rank-(rest)) = orgRank Then 
						vRest = vRest + 1
					Else
						vRest = 0
					End If 

					'vRank = (rank - rest) + vRest

					orgRank = rank - rest
					
					vRank = Replace(orgRank,"00","")
					'If Right(vRank,1) <> "0" Then vRank = Replace(vRank,"0","-") End If 
					printStr = printStr & "		<tr>" & vbcrlf
					If oldRank = orgRank Then 
						rowNo = rowNo+1
					Else
						printStr = Replace(printStr,"#rowSpan","rowspan=""" & rowNo & """")
						rowNo = 1
						printStr = printStr & "			<td class=""P_0rbl"" style=""text-align:right;height:30px;font-size:11px;padding-right:5px"" #rowSpan>" & vRank & "&nbsp;</td>" & vbcrlf
						printStr = printStr & "			<td class=""P_0rb0"" style=""text-align:center;height:30px;font-size:11px;padding-left:13px"" #rowSpan>" & procNm & "&nbsp;</td>" & vbcrlf
					End If 
					printStr = printStr & "			<td class=""P_0rb0"" style=""text-align:center;height:30px;font-size:11px;"">" & userNm & "&nbsp;</td>" & vbcrlf
					printStr = printStr & "			<td class=""P_0rb0"" style=""text-align:center;height:30px;font-size:11px;"">" & workDt & "&nbsp;</td>" & vbcrlf
					printStr = printStr & "			<td class=""P_0rb0"" style=""text-align:center;height:30px;font-size:11px;"">" & working & "&nbsp;</td>" & vbcrlf
					printStr = printStr & "			<td class=""P_0rb0"" style=""text-align:center;height:30px;font-size:11px;"">" & execTime & "&nbsp;</td>" & vbcrlf
					printStr = printStr & "		</tr>" & vbcrlf
					oldRank = orgRank

				procRs.movenext
				Loop 
			End If
			printStr = Replace(printStr,"#rowSpan","rowspan=""" & rowNo & """")
			Response.write printStr
		%>
	</table>
	<table border="0" width="99.5%" cellpadding="0" cellspacing="0">
		<tr>
			<td align="right" width="99.5%"><img src="<%=Request.Cookies("conf_compImg")%>" width="150"></td>
		</tr>
	</table>
</BODY>
</HTML>
<%session.codepage="949"%>